package com.eazyimage.lab.controller;

import com.eazyimage.lab.entity.Response;
import com.eazyimage.lab.entity.parmas.UploadFileMsgParam;
import com.eazyimage.lab.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author Pzi
 * @create 2022-05-03 15:22
 */
@RestController
@RequestMapping("/uploadData")
public class UploadDataController {

    @Autowired
    private UploadService uploadService;

    //  上传文件的同时，并且添加对该文件的描述
    //  上传文件，只能是zip。上传后数据库要记录该文件的id、描述、文件保存的路径、上传用户

    /**
     *
     * @param file  用户上传的zip文件
     * @return  返回zip文件所在的路径
     * @throws IOException
     */
    @PostMapping("/upload")
    public Response upload(@RequestParam("file") MultipartFile file, UploadFileMsgParam uploadFileMsgParam) throws IOException {
        return uploadService.upload(file,uploadFileMsgParam);
    }

    /**
     * 将用户上传成功后的文件信息等存入数据库中
     * @param uploadFileMsgParam 用户上传的文件路径、userName、文件描述
     * @return
     */
/*    @PostMapping("/uploadFileMsg")
    public Response uploadFileMsg(@RequestBody UploadFileMsgParam uploadFileMsgParam){
        return uploadService.uploadFileMsg(uploadFileMsgParam);
    }*/

}
